package company.alibaba;

import java.util.*;

//找两个数字的异或值接近目标数
public class Alibaba1 {
    //最小 000000000 32位
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        Map<Integer, Integer> map = new HashMap<>();
        int num;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            for (int j = 0; j < Integer.MAX_VALUE; j++) {
                num = i ^ j;
                map.put(num, map.getOrDefault(num, 0) + 1);
            }
        }
        int tmp, minOffset = Integer.MAX_VALUE, lastResult = 0, left, right, mid;
        for (int i = 0; i < n; i++) {
            //二分找到这个数
            left = 0;
            right = Integer.MAX_VALUE;
            tmp = x[i];
            if (map.containsKey(tmp))
                System.out.println(map.get(tmp));
            else {
                while (left <= right) {
                    mid = left + (right - left) >> 1;
                    if (Math.abs(mid - tmp) < minOffset && map.containsKey(mid))
                        lastResult = map.get(mid);
                    if (mid < tmp)
                        left = mid + 1;
                    else
                        right = mid - 1;
                }
                System.out.println(lastResult);
            }
        }
    }
}
